(comint-filter): New function.
authorRichard M. Stallman <rms@gnu.org>
Thu, 6 May 1993 19:51:08 +0000 (19:51 +0000)
committerRichard M. Stallman <rms@gnu.org>
Thu, 6 May 1993 19:51:08 +0000 (19:51 +0000)
(comint-exec): Install the filter.

lisp/comint.el

index 5f6d8301c01639157d52c27cff281e0588f89104..5c0d27ccb8910855811ff455bd3592fd1f5adb64 100644 (file)
@@ -330,6 +330,7 @@ buffer.  The hook comint-exec-hook is run after each exec."
       (if proc (delete-process proc)))
     ;; Crank up a new process
     (let ((proc (comint-exec-1 name buffer command switches)))
+      (set-process-filter proc 'comint-filter)
       (make-local-variable 'comint-ptyp)
       (setq comint-ptyp process-connection-type) ; T if pty, NIL if pipe.
       ;; Jump to the end, and set the process mark.
@@ -594,7 +595,7 @@ point as input to the process.  Before the process output mark, calls value
 of variable `comint-get-old-input' to retrieve old input, copies it to the
 process mark, and sends it.  If variable `comint-process-echoes' is `nil',
 a terminal newline is also inserted into the buffer and sent to the process
-(if it is non-`nil', all text from the process mark to point is deleted,
+\(if it is non-`nil', all text from the process mark to point is deleted,
 since it is assumed the remote process will re-echo it).  The value of
 variable `comint-input-sentinel' is called on the input before sending it.
 The input is entered into the input history ring, if the value of variable
@@ -645,6 +646,43 @@ Similarly for Soar, Scheme, etc."
          (set-marker comint-last-input-end (point))
          (set-marker (process-mark proc) (point))))))
 
+;; The sole purpose of using this filter for comint processes
+;; is to keep comint-last-input-end from moving forward
+;; when output is inserted.
+(defun comint-filter (process string)
+  (let ((obuf (current-buffer))
+       ordonly
+       opoint obeg oend)
+    (set-buffer (process-buffer process))
+    (setq opoint (point))
+    (setq obeg (point-min))
+    (setq oend (point-max))
+    (setq ordonly buffer-read-only)
+    (let ((buffer-read-only nil)
+         (nchars (length string)))
+      (widen)
+      (goto-char (process-mark process))
+      (setq opoint (+ opoint nchars))
+      ;; Insert after old_begv, but before old_zv.
+      (if (< (point) obeg)
+         (setq obeg (+ obeg nchars)))
+      (if (<= (point) oend)
+         (setq oend (+ oend nchars)))
+
+      (insert-before-markers string)
+      (and comint-last-input-end
+          (marker-buffer comint-last-input-end)
+          (= (point) comint-last-input-end)
+          (set-marker comint-last-input-end
+                      (- comint-last-input-end nchars)))
+      (set-marker (process-mark process) (point) nil)
+      (force-mode-line-update)
+
+      (narrow-to-region obeg oend)
+      (setq buffer-read-only ordonly)
+      (goto-char opoint)
+      (set-buffer obuf))))
+
 (defun comint-get-old-input-default ()
   "Default for comint-get-old-input.
 Take the current line, and discard any initial text matching